package com.aooci.ordercat.service.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.aooci.ordercat.dao.DiningTableDAO;
import com.aooci.ordercat.dao.ItemCategoryDAO;
import com.aooci.ordercat.dao.TakeawayDAO;
import com.aooci.ordercat.domain.DiningTable;
import com.aooci.ordercat.domain.ItemCategory;
import com.aooci.ordercat.domain.Takeaway;
import com.aooci.ordercat.enums.OrderType;
import com.aooci.ordercat.enums.TakeawayStatus;
import com.aooci.ordercat.service.DashboardService;
import com.aooci.ordercat.vo.ItemVo;

@Service("dashboardService")  
@Transactional
public class DashboardServiceImpl implements DashboardService, Serializable {

	private static final long serialVersionUID = -1193474493259273334L;

	private DiningTableDAO diningTableDAO;
	public void setDiningTableDAO(DiningTableDAO diningTableDAO) {
		this.diningTableDAO = diningTableDAO;
	}
	
	private TakeawayDAO takeawayDAO;
	public void setTakeawayDAO(TakeawayDAO takeawayDAO) {
		this.takeawayDAO = takeawayDAO;
	}

	private List<ItemCategory> itemCategories;

	private ItemCategoryDAO itemCategoryDAO;
	public void setItemCategoryDAO(ItemCategoryDAO itemCategoryDAO) {
		this.itemCategoryDAO = itemCategoryDAO;
	}


	public void init() {
		
	}
	
	@Override
	public List<DiningTable> loadDiningTables() {
		return this.diningTableDAO.findAll();
	}

//	@Override
//	public OrderOperationVo loadOrderOperationVoToDiningTable(
//			int diningTableId) {
//		DiningTableVo diningTableVo = diningTableMap.get(diningTableId);
//		OrderOperationVo operationDetailVo = new OrderOperationVo();
//		operationDetailVo.setOrderType(OrderType.DINING_HALL);
//		operationDetailVo.setDiningTableName(diningTableVo.getName());
//		operationDetailVo.setDiningTableStatus(diningTableVo.getStatus());
//		return operationDetailVo;
//	}

	@Override
	public void ordertItemFromCategore(int orderId, OrderType orderType,
			int itemId, int itemCount) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public List<ItemCategory> loadItemCategories() {
		if(itemCategories == null){
			itemCategories = itemCategoryDAO.findAll();
		}
		return itemCategories;
	}

	@Override
	public List<ItemVo> loadItemsByItemCategoryId(int itemCategoryId) {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public List<DiningTable> loadDiningTablesByCategoryId(int diningTableCategoryId) {
		return this.diningTableDAO.findTableByCategoryId(diningTableCategoryId);
	}


	@Override
	public List<Takeaway> loadNoFreeTakeaways() {
		List<Takeaway> takeaways = this.takeawayDAO.findTakeawaysByStatus(TakeawayStatus.OCCUPIED);
		takeaways.addAll(this.takeawayDAO.findTakeawaysByStatus(TakeawayStatus.PAID));
		return takeaways;
	}


	@Override
	public Takeaway loadOneFreeTakeaway() {
		return this.takeawayDAO.findTakeawaysByStatus(TakeawayStatus.FREE).get(0);
	}


}
